package ProxyTest.Test;

import ProxyTest.interfaces.StudentMapper;
import TestCode.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class ProxyMain {
    public static void main(String[] args) throws IOException {
        //定义文件位置
        String resource = "mybatis-config.xml";
        //获取输入流
        InputStream inputStream = Resources.getResourceAsStream(resource);
        //基于配置文件构建工厂SqlSessionFactory
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try (SqlSession session = sessionFactory.openSession()) {
            StudentMapper mapper = session.getMapper(StudentMapper.class);
            List<Student> students = mapper.student();
            students.forEach(System.out::println);
        }
    }
}
